//
//  EaseBubbleView+ChatRecommand.m
//  SISSAPP
//
//  Created by 优房网 on 2017/6/27.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "EaseBubbleView+ChatRecommend.h"

static char _recommendTitleLabel_;
static char _firstTextLabel_;
static char _sectTextLabel_;
@implementation EaseBubbleView (ChatRecommend)

- (void)setupChatRecommandBubbleView {
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = [UIColor whiteColor];
    [self.backgroundImageView addSubview:titleLabel];
    self.recommendTitleLabel = titleLabel;
    
    UILabel *firstLabel = [[UILabel alloc] init];
    firstLabel.textColor = [UIColor whiteColor];
    firstLabel.font = [UIFont systemFontOfSize:15];
    firstLabel.numberOfLines = 0;
    [self.backgroundImageView addSubview:firstLabel];
    self.firstTextLabel = firstLabel;
    
    UILabel *secondLabel = [[UILabel alloc] init];
    secondLabel.textColor = [UIColor whiteColor];
    secondLabel.font = [UIFont systemFontOfSize:15];
    secondLabel.numberOfLines = 0;
    [self.backgroundImageView addSubview:secondLabel];
    self.secondTextLabel = secondLabel;

    
    [self _setupRecommandConstraints];
}

- (void)_setupRecommandConstraints{
    
    CGFloat offset = 8.0;
    [self.recommendTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backgroundImageView).offset(offset * 2);
        make.left.equalTo(self.backgroundImageView).offset(offset * 2);
    }];
    
    [self.firstTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.recommendTitleLabel);
        make.top.equalTo(self.recommendTitleLabel.mas_bottom).offset(offset);
    }];
    
    [self.secondTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.firstTextLabel);
        make.top.equalTo(self.firstTextLabel.mas_bottom).offset(offset);
    }];
}

- (void)updateChatRecommandMargin:(UIEdgeInsets)margin {
    
    if (_margin.top == margin.top && _margin.bottom == margin.bottom && _margin.left == margin.left && _margin.right == margin.right) {
        return;
    }
    _margin = margin;
    
//    [self removeConstraints:self.marginConstraints];
    [self _setupRecommandConstraints];
}



#pragma mark - getter and setter
- (void)setRecommendTitleLabel:(UILabel *)recommendTitleLabel {
    objc_setAssociatedObject(self, &_recommendTitleLabel_, recommendTitleLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (UILabel *)recommendTitleLabel {
    return objc_getAssociatedObject(self, &_recommendTitleLabel_);
}

- (void)setFirstTextLabel:(UILabel *)firstTextLabel {
    objc_setAssociatedObject(self, &_firstTextLabel_, firstTextLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (UILabel *)firstTextLabel {
    return objc_getAssociatedObject(self, &_firstTextLabel_);
}

- (void)setSecondTextLabel:(UILabel *)secondTextLabel {
    objc_setAssociatedObject(self, &_sectTextLabel_, secondTextLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (UILabel *)secondTextLabel {
    return objc_getAssociatedObject(self, &_sectTextLabel_);
}

@end
